package com.jielihaofeng.netty.bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;

import static com.jielihaofeng.netty.bytebuf.TestByteBuf.log;

/**
 * @author Johnnie Wind
 * @description 测试 Unpooled 工具类
 * @date 2021/11/12 09:38
 */
public class TestUnpooled {
    public static void main(String[] args) {
        // 先创建两个 ByteBuf：buf1 和 buf2
        ByteBuf buf1 = ByteBufAllocator.DEFAULT.buffer(5);
        buf1.writeBytes(new byte[]{1, 2, 3, 4, 5});
        ByteBuf buf2 = ByteBufAllocator.DEFAULT.buffer(5);
        buf2.writeBytes(new byte[]{6, 7, 8, 9, 10});
        // 使用 Unpooled 的 wrappedBuffer 方法进行包装
        ByteBuf byteBuf = Unpooled.wrappedBuffer(buf1, buf2);
//        log(byteBuf);

        // 包装普通的字节数组
        ByteBuf buffer = Unpooled.wrappedBuffer(new byte[]{1, 2, 3, 4, 5}, new byte[]{6, 7, 8, 9, 10});
        log(buffer);
    }
}
